package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DatabaseInfo;
import com.ruoyi.system.service.IDatabaseInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务数据库Controller
 * 
 * @author chenming
 * @date 2024-10-16
 */
@RestController
@RequestMapping("/system/baseInfo")
public class DatabaseInfoController extends BaseController
{
    @Autowired
    private IDatabaseInfoService databaseInfoService;

    /**
     * 查询业务数据库列表
     */
    @PreAuthorize("@ss.hasPermi('system:baseInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(DatabaseInfo databaseInfo)
    {
        startPage();
        List<DatabaseInfo> list = databaseInfoService.selectDatabaseInfoList(databaseInfo);
        return getDataTable(list);
    }

    /**
     * 导出业务数据库列表
     */
    @PreAuthorize("@ss.hasPermi('system:baseInfo:export')")
    @Log(title = "业务数据库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DatabaseInfo databaseInfo)
    {
        List<DatabaseInfo> list = databaseInfoService.selectDatabaseInfoList(databaseInfo);
        ExcelUtil<DatabaseInfo> util = new ExcelUtil<DatabaseInfo>(DatabaseInfo.class);
        util.exportExcel(response, list, "业务数据库数据");
    }

    /**
     * 获取业务数据库详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:baseInfo:query')")
    @GetMapping(value = "/{databaseId}")
    public AjaxResult getInfo(@PathVariable("databaseId") Long databaseId)
    {
        return success(databaseInfoService.selectDatabaseInfoByDatabaseId(databaseId));
    }

    /**
     * 新增业务数据库
     */
    @PreAuthorize("@ss.hasPermi('system:baseInfo:add')")
    @Log(title = "业务数据库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DatabaseInfo databaseInfo)
    {
        return toAjax(databaseInfoService.insertDatabaseInfo(databaseInfo));
    }

    /**
     * 修改业务数据库
     */
    @PreAuthorize("@ss.hasPermi('system:baseInfo:edit')")
    @Log(title = "业务数据库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DatabaseInfo databaseInfo)
    {
        return toAjax(databaseInfoService.updateDatabaseInfo(databaseInfo));
    }

    /**
     * 删除业务数据库
     */
    @PreAuthorize("@ss.hasPermi('system:baseInfo:remove')")
    @Log(title = "业务数据库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{databaseIds}")
    public AjaxResult remove(@PathVariable Long[] databaseIds)
    {
        return toAjax(databaseInfoService.deleteDatabaseInfoByDatabaseIds(databaseIds));
    }
}
